//default.aspx
//First step:Take a grid view and checkbox
<asp:GridView ID="GridView1" runat="server" Height="131px" Width="500px" DataKeyNames="Id"
AutoGenerateColumns="False" Style="margin-top: 2px; margin-left: 0px; margin-bottom: 1px;">
<Columns>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:CheckBox ID="chkRow" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</columns>
//default.cs
//second step:take a button for select all checkbox
//double click on button and write code
protected void Button2_Click(object sender, EventArgs e)
{
CheckState(b);//this is function
}
//make global variable
bool b=true;
//make a function
private void CheckState(bool p)
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox chkcheck = (CheckBox)row.FindControl("chkRow");
chkcheck.Checked = p;
}
}
Leave Comment